package com.yanqu.road.server.cmd.activity.unionchest;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.UnionChestProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.unionchest.UnionChestModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNIONCHEST_BOX_OPEN, desc = "开宝箱")
public class UnionChestOpenCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        UnionChestProto.UnionChestBoxOpenBoxReqMsg req = UnionChestProto.UnionChestBoxOpenBoxReqMsg.parseFrom(packet.getBytes());
        ret = player.getModule(UnionChestModule.class).openBox(req);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (0 != ret) {
            player.sendPacket(ClientProtocol.U_UNIONCHEST_BOX_OPEN, UnionChestProto.UnionChestBoxOpenBoxRespMsg.newBuilder().setRet(ret));
        }
    }
}
